The fact that optional parameters' default values are only evaluated once,
can lead to some unintuitive outcomes.
So, here, we define a function that has two arguments,
a and L. L's default value is an empty list.
Now, note again that because this value is only evaluated once,
what that means is that we have an empty list that
lives somewhere in the frames in objects as the default value for L. So,
here after we defined our function f,
then we first print out f called with the value one.
Now, in the body of f we actually mutate the value of L. So, what that means,
is that when we call f on line five we pass in one for
a and L is going to be that empty list that we created right here.
When we run line two to say L.append a then we append one
to our empty list and now our list is a list that has one item whose value is one.
Now, on line three we return that list L. But,
the thing to note here is that even though this list is going to go away in CodeLens,
it actually keeps its value of a list that has one item whose value is one.
So, even though this disappears in CodeLens,
by the time we get to line six this list still has the value one.
So, now, on line six when we call f with a equals two,
then you can see that L is this list that has one item in it already.
So, now, on line two when we append a to our list we add two onto this list.
So, we're going to say,
list is now a list that has one and two in it.
So, if we kept calling our function f to add new values to our list,
then we would get a longer and longer list as our default value for L. So, here,
by the time we get to line seven and we call f with three,
then when we call this function our list L already has two values in it,
and on line two we add three on as a third value in our list.
So, the important thing to note again here is that as
our default value gets mutated it affects feature calls to this function f. Now,
an important distinction here,
is distinguishing between lists that are different objects,
but have the same value versus this list,
which is the same object.
So, for example, on lines eight and nine,
we pass in two different values for L. On line eight,
we pass in a list that has the string "Hello" as its one item.
On line nine, we pass in a list that looks identical,
but because these are separate expressions,
then these are actually separate objects.
What that means, is that by the time we get to line
eight and we print out the value of f called with a equals four,
and L equals the list with the item "Hello."
Then, when we actually call L.append a,
then we're mutating this list,
and that has no effect on this list.
So, here we're mutating this list to add four onto it,
which you can see here,
and then when we get to line nine,
then we're mutating a different list.
So, note again here that we have a list
whose only value is "Hello" it doesn't have the four that we added on to this list.
That's all for now, until next time.